package com.bsoft.exchange.service;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsoft.exchange.dao.his.NumberMapper;
import com.bsoft.exchange.dao.his.SystemConfigMapper;
import com.bsoft.exchange.domain.Number;
import com.bsoft.exchange.pojo.ListNumberPojo;
import com.bsoft.exchange.util.DateUtil;
import com.bsoft.exchange.util.TimeUtil;

@Service
public class NumberService {

    @Autowired
    NumberMapper numberMapper;
    @Autowired
    SystemConfigMapper systemConfigMapper;

    public List<Number> selectList(ListNumberPojo listNumberPojo) {
        Date startdate = null;
        Date enddate = null;
        Date pbrq = null;
        Date pbrq1 = null;
        Date qssj = null;
        Date jzsj = null;
        SimpleDateFormat strat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat strat1 = new SimpleDateFormat("yyyy-MM-dd");
        String doctorTime = listNumberPojo.getScheduleDate();


        try {
            if (doctorTime == null || "".equals(doctorTime)) {
                pbrq = new Date();
                Long jgidLong = Long.valueOf(listNumberPojo.getOrganizationId());
                int ts = Integer.valueOf(systemConfigMapper.getValueByConfigName(jgidLong, "GHYY_SCHYTS"));
                pbrq1 = DateUtil.addDateToDay(pbrq, ts);
                //默认开放今天的号源
                pbrq = DateUtil.addDateToDay(pbrq, 1);

//                if (listNumberPojo.getPeriodId() == 1) {
//                    String day = DateUtil.dateFormatDay(pbrq);
//                    day += " 08:00:00";
//                    qssj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//                    day = DateUtil.dateFormatDay(pbrq);
//                    day += " 11:00:00";
//                    jzsj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//                } else if (listNumberPojo.getPeriodId() == 2) {
//                    String day = DateUtil.dateFormatDay(pbrq);
//                    day += " 14:00:00";
//                    qssj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//                    day = DateUtil.dateFormatDay(pbrq);
//                    day += " 15:00:00";
//                    jzsj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//                }

            } else {
                pbrq = DateUtil.stringToDate(doctorTime);
                pbrq1 = DateUtil.addDateToDay(pbrq, 1);

//                if (listNumberPojo.getPeriodId() == 1) {
//					Date date = DateUtil.StrToFormatDate(doctorTime, "yyyy-MM-dd HH:mm:ss");
//					String day = DateUtil.dateFormatDay(date);
//					day += " 08:00:00";
//					qssj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//					day = DateUtil.dateFormatDay(date);
//					day += " 11:00:00";
//					jzsj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//				} else if (listNumberPojo.getPeriodId() == 2) {
//					Date date = DateUtil.StrToFormatDate(doctorTime, "yyyy-MM-dd HH:mm:ss");
//					String day = DateUtil.dateFormatDay(date);
//					day += " 14:00:00";
//					qssj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//					day = DateUtil.dateFormatDay(date);
//					day += " 15:00:00";
//					jzsj = DateUtil.StrToFormatDate(day, "yyyy-MM-dd HH:mm:ss");
//                }

            }
            String date1 = strat1.format(pbrq);
            String date2 = strat1.format(pbrq1);
            startdate = strat.parse(date1 + " 00:00:00");
            enddate = strat.parse(date2 + " 00:00:00");
        } catch (Exception e) {
            e.printStackTrace();
        }


        List<Number> number = numberMapper.selectList(listNumberPojo.getOrganizationId(),
                listNumberPojo.getDepartmentId(),
                listNumberPojo.getDoctorId(),
                startdate,
                enddate,
                listNumberPojo.getDoctorType(),
                listNumberPojo.getPeriodId(),
                listNumberPojo.getOutpatientType(),
                listNumberPojo.getLastModifyTime());

        return number;

    }


}